﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using palmApp.Database;

namespace palmApp
{
    public partial class newMachineScreen : Form
    {
        public newMachineScreen()
        {
            InitializeComponent();

            for (Int32 i = DateTime.Now.Year; i >= 1920; i--)
            {
                this.comboBox1.Items.Add(i);
            }

            this.ShowDialog();
        }
        
        private Boolean IsFormEmpty()
        {
            if (textBox1.Text != "" && textBox2.Text != "" && textBox3.Text != "" && textBox4.Text != "" && textBox5.Text != "" && textBox7.Text != "" && textBox8.Text != "" && textBox9.Text != "")
            {
                return (true);
            }
            return (false);
        }

        private void menuItem1_Click(object sender, EventArgs e)
        {
            String tag_machine = new System.Random().Next(13499421, 79752999).ToString();

            this.textBox1.Text = tag_machine;
        }

        private void menuItem11_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void menuItem9_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void menuItem8_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void menuItem7_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";
            textBox2.Text = "";
            textBox3.Text = "";
            textBox5.Text = "";
            textBox7.Text = "";
            comboBox1.SelectedIndex = -1;
        }

        private void menuItem6_Click(object sender, EventArgs e)
        {
            menuItem7_Click(sender, e);
        }

        private void tabPage1_Click(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void label8_ParentChanged(object sender, EventArgs e)
        {

        }

        private void label2_ParentChanged(object sender, EventArgs e)
        {

        }

        private void menuItem4_Click(object sender, EventArgs e)
        {
            if (!IsFormEmpty())
            {
                /*
                Stack<Object> data = new Stack<Object>();

                data.Push(textBox1.Text);
                data.Push(textBox1.Text);
                data.Push(textBox1.Text);
                data.Push(textBox1.Text);
                data.Push(textBox1.Text);

                Manager maintenanceMan = new Manager();
                Int32 result = maintenanceMan.NewOperation(data.ToArray());
                maintenanceMan.Close();
                 * */

                //if (result != -1)
                if(true)
                {
                    DialogResult dlgRes = MessageBox.Show(
                        string.Format("¡Los datos se han guardado satisfactoriamente!"),
                        "Nueva máquina",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Exclamation,
                        MessageBoxDefaultButton.Button1
                        );
                    if (dlgRes == DialogResult.OK)
                    {
                        this.Close();
                    }
                }
            }
        }
    }
}